using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;


namespace MOSS_Deploment_Wizard
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            // Ah yes, more ego stroking... Yes, I wrote this app, so there.
            MessageBox.Show("Written (poorly) by Duane Wolff", "About MOSS Deployment Wizard: Copyright 2009 by Duane Wolff");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Path variable is set to the value of textBox1
            string path = textBox1.Text;
            // We'll read all WSP's from selected subfolder
            DirectoryInfo diFiles = new DirectoryInfo(path);
            // We display all files with the extension WSP in the list box control
            lbPackages.DataSource = diFiles.GetFiles("*.wsp");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // Runs the add solution commands in STSADM.EXE then puts the concatenated command into the log
            System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm.exe", @" -o addsolution -filename " + textBox1.Text + "\\" + lbPackages.SelectedItem);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            // Runs the retract solution commands in STSADM.EXE
            System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm.exe", @" -o retractsolution -name " + lbPackages.SelectedItem + " -immediate");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            // Runs the delete solution commands in STSADM.EXE
            System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\\stsadm.exe", @" -o deletesolution -name " + lbPackages.SelectedItem);
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Exits the application
            Application.Exit();
        }

        private void retractToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Runs the add solution commands in STSADM.EXE then puts the concatenated command into the log
            System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm.exe", @" -o addsolution -filename " + textBox1.Text + "\\" + lbPackages.SelectedItem);
        }

        private void retractToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            // Runs the retract solution commands in STSADM.EXE
            System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm.exe", @" -o retractsolution -name " + lbPackages.SelectedItem + " -immediate");
        }

        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Runs the delete solution commands in STSADM.EXE
            System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\\stsadm.exe", @" -o deletesolution -name " + lbPackages.SelectedItem);
        }

        private void deploySolutionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Deploys the selected solution and forces it to the GAC (-allowgacdeployment)
            System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm.exe", @" -o deploysolution -name " + lbPackages.SelectedItem + " -local -allowgacdeployment");
        }

    }
}